home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / graphics / graphics_init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-12  |  3.9 KB  |  171 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: graphics_init.c,v 1.3 1996/09/11 16:54:24 digulla Exp $
  4.     $Log: graphics_init.c,v $
  5.     Revision 1.3  1996/09/11 16:54:24  digulla
  6.     Always use __AROS_SLIB_ENTRY() to access shared external symbols, because
  7.         some systems name an external symbol "x" as "_x" and others as "x".
  8.         (The problem arises with assembler symbols which might differ)
  9.  
  10.     Revision 1.2  1996/08/13 14:00:53  digulla
  11.     Added calls to driver
  12.     Init local SysBase
  13.     Replaced __AROS_LA with __AROS_LHA
  14.  
  15.     Revision 1.1  1996/08/12 14:27:50  digulla
  16.     Base of graphics library
  17.  
  18.     Revision 1.2  1996/08/01 17:41:42  digulla
  19.     Added standard header for all files
  20.  
  21.     Desc:
  22.     Lang:
  23. */
  24. #include <exec/resident.h>
  25. #include <clib/exec_protos.h>
  26. #include <aros/libcall.h>
  27. #include <dos/dos.h>
  28. #include <exec/execbase.h>
  29. #include <graphics/gfxbase.h>
  30. #include "graphics_intern.h"
  31.  
  32. static const char name[];
  33. static const char version[];
  34. static const APTR inittabl[4];
  35. static void *const Graphics_functable[];
  36. struct GfxBase * __AROS_SLIB_ENTRY(init,Graphics)();
  37. extern const char Graphics_end;
  38.  
  39. extern int  driver_init (struct GfxBase *);
  40. extern int  driver_open (struct GfxBase *);
  41. extern void driver_close (struct GfxBase *);
  42. extern void driver_expunge (struct GfxBase *);
  43.  
  44. int Graphics_entry(void)
  45. {
  46.     /* If the library was executed by accident return error code. */
  47.     return -1;
  48. }
  49.  
  50. const struct Resident Graphics_resident=
  51. {
  52.     RTC_MATCHWORD,
  53.     (struct Resident *)&Graphics_resident,
  54.     (APTR)&Graphics_end,
  55.     RTF_AUTOINIT,
  56.     39,
  57.     NT_LIBRARY,
  58.     0,
  59.     (char *)name,
  60.     (char *)&version[6],
  61.     (ULONG *)inittabl
  62. };
  63.  
  64. static const char name[]=GRAPHICSNAME;
  65.  
  66. static const char version[]="$VER: graphics.library 39.0 (12.8.96)\n\015";
  67.  
  68. static const APTR inittabl[4]=
  69. {
  70.     (APTR)sizeof(struct GfxBase),
  71.     (APTR)Graphics_functable,
  72.     NULL,
  73.     &__AROS_SLIB_ENTRY(init,Graphics)
  74. };
  75.  
  76. __AROS_LH2(struct GfxBase *, init,
  77.  __AROS_LHA(struct GfxBase *, GfxBase, D0),
  78.  __AROS_LHA(BPTR,               segList,   A0),
  79.        struct ExecBase *, sysBase, 0, Graphics)
  80. {
  81.     __AROS_FUNC_INIT
  82.  
  83.     SysBase = sysBase;
  84.  
  85.     if (!driver_init (GfxBase))
  86.     return NULL;
  87.  
  88.     /* You would return NULL if the init failed */
  89.     return GfxBase;
  90.     __AROS_FUNC_EXIT
  91. }
  92.  
  93. __AROS_LH1(struct GfxBase *, open,
  94.  __AROS_LHA(ULONG, version, D0),
  95.        struct GfxBase *, GfxBase, 1, Graphics)
  96. {
  97.     __AROS_FUNC_INIT
  98.  
  99.     /* Keep compiler happy */
  100.     version=0;
  101.  
  102.     if (!driver_open (GfxBase))
  103.     return NULL;
  104.  
  105.     /* I have one more opener. */
  106.     GfxBase->LibNode.lib_OpenCnt++;
  107.     GfxBase->LibNode.lib_Flags&=~LIBF_DELEXP;
  108.  
  109.     /* You would return NULL if the open failed. */
  110.     return GfxBase;
  111.     __AROS_FUNC_EXIT
  112. }
  113.  
  114. __AROS_LH0(BPTR, close,
  115.        struct GfxBase *, GfxBase, 2, Graphics)
  116. {
  117.     __AROS_FUNC_INIT
  118.  
  119.     /* I have one fewer opener. */
  120.     if(!--GfxBase->LibNode.lib_OpenCnt)
  121.     {
  122.     driver_close (GfxBase);
  123.  
  124.     /* Delayed expunge pending? */
  125.     if(GfxBase->LibNode.lib_Flags&LIBF_DELEXP)
  126.         /* Then expunge the library */
  127.         return expunge();
  128.     }
  129.     return 0;
  130.     __AROS_FUNC_EXIT
  131. }
  132.  
  133. __AROS_LH0(BPTR, expunge,
  134.        struct GfxBase *, GfxBase, 3, Graphics)
  135. {
  136.     __AROS_FUNC_INIT
  137.  
  138.     BPTR ret;
  139.  
  140.     /* Test for openers. */
  141.     if(GfxBase->LibNode.lib_OpenCnt)
  142.     {
  143.     /* Set the delayed expunge flag and return. */
  144.     GfxBase->LibNode.lib_Flags|=LIBF_DELEXP;
  145.     return 0;
  146.     }
  147.  
  148.     driver_expunge (GfxBase);
  149.  
  150.     /* Get rid of the library. Remove it from the list. */
  151.     Remove(&GfxBase->LibNode.lib_Node);
  152.  
  153.     /* Get returncode here - FreeMem() will destroy the field. */
  154.     ret=0L;
  155.  
  156.     /* Free the memory. */
  157.     FreeMem((char *)GfxBase-GfxBase->LibNode.lib_NegSize,
  158.         GfxBase->LibNode.lib_NegSize+GfxBase->LibNode.lib_PosSize);
  159.  
  160.     return ret;
  161.     __AROS_FUNC_EXIT
  162. }
  163.  
  164. __AROS_LH0I(int, null,
  165.         struct GfxBase *, GfxBase, 4, Graphics)
  166. {
  167.     __AROS_FUNC_INIT
  168.     return 0;
  169.     __AROS_FUNC_EXIT
  170. }
  171.